package concurrent.BlockingQueue;

import java.util.concurrent.*;

/**
 *  BlockingQueue 阻塞队列。首先，队列，符合先进先出规则。阻塞，是元素满时，无法放入对象，会阻塞；元素空时，无法取出对象，也会阻塞
 *  实现有：
 *  ArrayBlockingQueue, LinkedBlockingQueue
 *  PriorityBlockingQueue ，它的元素必须实现Comparable接口，定义什么是大，什么是小
 */
public class BlockingQueueExample {  
	  
    public static void main(String[] args) throws Exception {  
  
//        BlockingQueue queue = new ArrayBlockingQueue(50);  
    	BlockingQueue<String> queue = new PriorityBlockingQueue<String>();
  
        Producer producer = new Producer(queue);  
        Consumer consumer = new Consumer(queue);  
  
        new Thread(producer).start();  
        new Thread(consumer).start();  
  
        Thread.sleep(4000);  
        System.out.println("主线程结束");
    }  
}  
